package com.speedricemanager.other.utils;

import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import static com.speedricemanager.other.utils.TaoUtils.getPosition;


public class HttpPost {
    private static List<Integer> arrMoney=new ArrayList<>();
//    public static void exe(){
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                HttpPost http=new HttpPost();
//                String cookie="_tb_token_=e5lFtg81S2jPdjoHVVPL; v=0; cookie2=1e660a89df8e0ebac9dbc69c5f595ca7; mt=ci=5_1; thw=cn; _mw_us_time_=1508648630243; cna=RypyEr10v14CAW8gN8eAALDu; isg=As7OlaZIG9XzIa_2w3oROZbLFKZQ55KJlvVOhfgXOlGMW261YN_iWXQZw7_I; munb=2583164861; uc3=sg2=U7Zv98GYv0qzwhq%2FbFgRAuUI6qpqV5dkeb3XfP9cI%2FQ%3D&nk2=p2%2FT9gGew9Ancv28&id2=UU26%2F3%2BdZMoDXw%3D%3D&vt3=F8dBzLE1DAEqOYE%2BnJE%3D&lg2=W5iHLLyFOGW7aA%3D%3D; uc1=cookie14=UoTcBzld3LOxnw%3D%3D&cookie21=Vq8l%2BKCLjhS4UhJVbhgU&cookie15=VFC%2FuZ9ayeYq2g%3D%3D; lgc=%5Cu9B54%5Cu715E%5Cu98CE%5Cu884Cword; uss=VAMUHoYPibIUAt98fCXSECNjU83R9o1qjnm705KVTxyoK4OPy6%2BG%2Fy%2B11g%3D%3D; tracknick=%5Cu9B54%5Cu715E%5Cu98CE%5Cu884Cword; sg=d14; cookie1=BxNQV3v1wQAjIJUPIYeMPE6VNPy7l2AbrpgYNX7RSIQ%3D; unb=2583164861; skt=d71aecc5ed706dbc; t=b07bbc176468f6883428d9e6fa1c113a; _cc_=VT5L2FSpdA%3D%3D; _nk_=%5Cu9B54%5Cu715E%5Cu98CE%5Cu884Cword; _l_g_=Ug%3D%3D; cookie17=UU26%2F3%2BdZMoDXw%3D%3D";
//                String uruu="https://buyertrade.taobao.com/trade/itemlist/asyncBought.htm?action=itemlist/BoughtQueryAction&event_submit_do_query=1&_input_charset=utf8";
//                getOrderOne(cookie, uruu);
//            }
//        }).start();
//    }

    public static List<Integer> getOrderMonth(String cookie, String uruu) {
        arrMoney.clear();
        String   start= TaoUtils.getPastDate(30);
        String daa = TaoUtils.dateToStamp(start+" 0:00:00");
        String daa1 =TaoUtils.dateToStamp(TaoUtils.format());
        String str = getPosition(uruu, cookie, daa, daa1);//
        try {
            JSONObject oo=new JSONObject(str);
            JSONArray arrc = oo.getJSONArray("mainOrders");
            for (int i = 0; i <arrc.length() ; i++) {
                String actual = arrc.getJSONObject(i).getJSONObject("payInfo").getString("actualFee");
                Log.e("main","真实钱"+actual);
                arrMoney.add((int)Double.parseDouble(actual));
            }
            Log.e("main","长度"+arrc.length());

        }catch (Exception e){
            Log.e("main","长度错误"+e.getMessage());
        }
        return arrMoney;
    }
    public static int getOrderWeek(String cookie, String uruu) {
        int len = 0;
        String   start= TaoUtils.getPastDate(7);
        String daa = TaoUtils.dateToStamp(start+" 0:00:00");
        String daa1 =TaoUtils.dateToStamp(TaoUtils.format());
        String str = getPosition(uruu, cookie, daa, daa1);//
        try {
            JSONObject oo=new JSONObject(str);
            JSONArray arrc = oo.getJSONArray("mainOrders");
            len=arrc.length();
            Log.e("main","长度"+arrc.length());
        }catch (Exception e){
            Log.e("main","长度错误"+e.getMessage());
        }
        return len;
    }
    public static int getOrderOne(String cookie, String uruu) {
        int len=0;
        String   start= TaoUtils.getPastDate(0);
        String daa = TaoUtils.dateToStamp(start+" 0:00:00");
        String daa1 =TaoUtils.dateToStamp(TaoUtils.format());
        String str = getPosition(uruu, cookie, daa, daa1);//
        try {
            JSONObject oo=new JSONObject(str);
            JSONArray arrc = oo.getJSONArray("mainOrders");
            len=arrc.length();
            Log.e("main","长度"+arrc.length());
        }catch (Exception e){
            Log.e("main","长度错误"+e.getMessage());
        }
return len;
    }
}
